package 线程池.JUC;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author caihe
 * @date 2022/11/7 10:48
 */
public class ReentrantLockTest {
    final static ReentrantLock lock = new ReentrantLock(true);
    
    public static void main(String[] args) {
        new Thread(() -> {
            test();
        }, "线程A").start();
        new Thread(() -> {
            test();
        }, "线程B").start();
        new Thread(() -> {
            test();
        }, "线程C").start();
//        test();
        System.out.println();

    }
    
    private static void test() {
        lock.lock();
        try {
            System.out.println("加锁成功");
        }catch (Exception e) {
            
        } finally {
            lock.unlock();
            System.out.println("解锁成功");
        }
        
    }
}
